{{template "member/top.html" .}}

<style>
.img-src {
	max-height: 200px;
}
</style>

<div class="m-b-md"> <h3 class="m-b-none">
{{.note.Title}} - {{msg $ "setAbstract"}}
</h3>
</div>

<link rel="stylesheet" href="/css/tinymce/skin.min.css" type="text/css">

<div class="row">
<div class="col-sm-10">
	<form id="formData">
		<section class="panel panel-default">
			<div class="panel-body">

				{{leaMsg . "Once the abstract has been updated, it will not set the abstract automatically other than you cancel it."}}

				<hr />
  				<div class="alert alert-danger" id="baseMsg" style="display: none"></div>
  				
				<div class="form-group" id="mainImg">
					<label>
						{{leaMsg $ "Main Image"}}
						<a class="btn btn-default btn-select-img">
							{{leaMsg $ "Get next image as main image from content"}}
						</a>
					</label>
					<div style="border: 2px dashed #ccc; padding: 5px;">
						<img src="{{.note.ImgSrc}}" class="img-src" id="imgSrc"/>
					</div>
				</div>
				
				<div class="form-group">
					<label>{{leaMsg $ "Description" }}</label>
					<textarea type="text" rows="6" class="form-control" id="desc" name="desc">{{.note.Desc}}</textarea>
				</div>
				
				<div class="form-group">
					<label for="content1">{{leaMsg $ "Abstract"}}</label>
					<div class="toolbar-content">
						<div id="popularToolbar" class="tool-bar"></div>
						<div id="content1" class="content-ctn" name="content">{{raw .note.Abstract}}</div>
					</div>
				</div>
			</div>
			<footer class="panel-footer text-right bg-light lter">
			    <button type="submit" id="submitBtn" class="btn btn-success">{{msg . "submit"}}</button>
			</footer>

			<div class="panel-body">
				<p>
				{{leaMsg . "Raw Content"}}:
				<hr />
				</p>
				<div id="rawContent">
					{{if .note.IsMarkdown}}
						<pre>{{.note.Content|raw}}</pre>
					{{else}}
						{{.note.Content|raw}}
					{{end}}
				</div>
			</div>
		</section>
	</form>
</div>

</div>
{{template "member/footer.html" .}}
<script type="text/javascript" src="/tinymce/tinymce.js"></script>
<script>
var UrlPrefix = "{{.siteUrl}}";
var LeaAce = null;
$(function() {
	tinymce.init({
		inline: true,
		selector : "#content1",
		theme: 'leanote',
		language : "{{.locale}}",
		plugins : [
				"advlist autolink link lists charmap hr ",
				"searchreplace visualblocks visualchars tabfocus",
				"table contextmenu directionality textcolor fullpage textcolor"],
		toolbar1 : "formatselect |fontselect fontsizeselect| forecolor backcolor | bold italic underline strikethrough | bullist numlist |",
		menubar : false,
		statusbar : false,
		font_formats : "Arial=arial,helvetica,sans-serif;"
				+ "Arial Black=arial black,avant garde;"
				+ "Times New Roman=times new roman,times;"
				+ "Courier New=courier new,courier;"
				+ "Tahoma=tahoma,arial,helvetica,sans-serif;"
				+ "Verdana=verdana,geneva;" + "宋体=SimSun;"
				+ "新宋体=NSimSun;" + "黑体=SimHei;"
				+ "微软雅黑=Microsoft YaHei",
		block_formats : "Header 1=h1;Header 2=h2;Header 3=h3; Header 4=h4;Pre=pre;Paragraph=p"
	});
	
	// 提交
	$("#submitBtn").click(function(e) {
		e.preventDefault();
		var data = {
			noteId: "{{.noteId}}",
			imgSrc: $("#imgSrc").attr("src"),
			desc : $("#desc").val(),
			abstract : getEditorContent()
		}
		ajaxPost("/member/blog/doUpdateBlogAbstract/", data, function(re) {
			if(reIsOk(re)) {
				art.tips(getMsg("Success"));
				location.href = "/member/blog/index";
			} else {
				art.alert(re.Msg || "error")
			}
		});
	});
	
	var isMarkdown = {{$.note.IsMarkdown}};
	
	var images = [];
	if (isMarkdown) {
		var content = $('#rawContent').html();
		var reg = /!\[.*?\]\((.*)\)/g;
		var ret = reg.exec(content);
		while(ret) {
			images.push(ret[1]);
			ret = reg.exec(content);
		}
		// console.log(images);
	}
	// 选择主图
	$("#rawContent").find("img").each(function () {
		if($(this).attr('src')) {
			images.push($(this).attr('src'));
		}
	});;
	var imgLen = images.length;
	var imgSeq = 0;
	$imgSrc = $('#imgSrc');
	
	if (imgLen) {
		$(".btn-select-img").click(function() {
			imgSeq++;
			imgSeq = imgSeq % imgLen;
			$imgSrc.attr("src", images[imgSeq]);
		});
	}
	else {
		$(".btn-select-img").hide();
	}
});
</script>

{{template "member/end.html" .}}